package utils

import (
	"fmt"
	"time"
)

// FormatTime 格式化时间显示
func FormatTime(t time.Time) string {
	now := time.Now()
	duration := now.Sub(t)

	if duration < time.Minute {
		return fmt.Sprintf("%d秒前", int(duration.Seconds()))
	} else if duration < time.Hour {
		return fmt.Sprintf("%d分钟前", int(duration.Minutes()))
	} else if duration < 24*time.Hour {
		return fmt.Sprintf("%d小时前", int(duration.Hours()))
	} else if duration < 7*24*time.Hour {
		return fmt.Sprintf("%d天前", int(duration.Hours()/24))
	} else {
		return t.Format("2006-01-02 15:04")
	}
}
